<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        // ES6 允许按照一定模式，从数组和对象中快速提取值，对变量进行赋值，这被称为解构（Destructuring）。

        // 1.基本用法(完全解构)
        let arr=["李子柒","谭金城","蔡伟楠"];
        let [a,b,c]=arr;
        console.log(a,b,c);

        // 2.不完全解构
        let [,,d,e]=["alice","tom","baby","cici"];
        console.log(d);
        console.log(e);

        //3.剩余解构，格式： ...变量名
        //    (1)剩余解构只对没有被取值的剩余数据进行数组包装
        //    (2)剩余解构的语法必须出现在解构模式化的最后一位

        let [arr1,...arr2]=["a","b","c","d","e","f"];
        // let [...arr1,...arr2]=["a","b","c","d","e","f"];//语法错误
        console.log(arr1);
        console.log(arr2);

        //4.模式匹配失败
        let [arrs]=[];
        console.log(arrs);

        //5.多维数组的嵌套解构
        let [,temp1,,[,temp2]]=["aa","bb","cc",["dd","ee","ff"]];
        console.log(temp1,temp2);

        let a1=5;
        let b1=3;
        [a1,b1]=[b1,a1];
        console.log(a1);
        console.log(b1);

    </script>
</head>
<body>
    
</body>
</html>